package com.liangge.essaysite.controller;

import java.util.HashMap;
import java.util.Map;

import javax.servlet.http.HttpServletRequest;

import net.sf.ehcache.Cache;
import net.sf.ehcache.Element;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;

import com.liangge.essaysite.bean.User;
import com.liangge.essaysite.service.UserService;
import com.liangge.essaysite.util.AgentKeys;
import com.liangge.essaysite.util.CfgUtils;

@Controller
@RequestMapping("/article")
public class ArticleController {
	private static Logger logger = LoggerFactory.getLogger(ArticleController.class);
	
	private UserService userService;
	private Cache ehCache;
	@Autowired @Qualifier("userService")
	public void setUserService(UserService userService) {
		this.userService = userService;
	}
	@Autowired @Qualifier("ehCacheDefault")
	public void setEhCache(Cache ehCache) {
		this.ehCache = ehCache;
	}


	/**
	 * 获取文章
	 * @author liangge
	 */
	@RequestMapping(value="/{articleId}",method=RequestMethod.GET)
	public String index(@PathVariable String articleId,HttpServletRequest request,Model model){
		Map<String,Object> params = new HashMap<String,Object>();
		params.put("username", "liangge");
		User user = userService.selectUserByUsername(params);
		if(user != null){
			logger.info("username:{},password:{}",user.getUsername(),user.getPassword());
		}else{
			logger.info("user is null!");
		}
		
//		Element e = new Element("name","baidu");
//		ehCache.put(e);
//		
//		System.out.println(ehCache.get("name"));
		return "index/article.ftl";
	}
}
